﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Utils;

namespace UI.ModSalesman
{
    public partial class RewardsList : System.Web.UI.Page
    {
        SalesmanBiz salesmanBiz = new SalesmanBiz();
        string saleManID = "0";     
  
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["SaleManID"] != null) saleManID = Request.Params["SaleManID"].ToString().Trim();
           
            if (!IsPostBack)
            {
              
                    new DepartmentBiz().InitDropDownList(ddlDeptID, "0");
                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('RewardsAdd.aspx',800,550);");
                //JSUtility.AddReset(btnClear);
                if (saleManID != "0")
                {

                    DataTable dt = salesmanBiz.GetRewardsLists(saleManID);
                    gvList.DataSource = dt;
                    gvList.DataBind();
                    lbAmount.Text = dt.Rows.Count.ToString();
                }
            }
        }
        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            string deptID = ddlDeptID.SelectedItem.Text.Trim();
            if (deptID == "请选择部门") deptID = "";
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string type = ddlType.SelectedValue;
            if (type=="0" && deptID == "" && string.IsNullOrEmpty(serWord) && string.IsNullOrEmpty(bTime))
            {
                bTime = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                txtBtime.Text = bTime;
                txtEtime.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
            }

            if (StringUtility.GetDiffDays(bTime, eTime) > XmlUtility.GetNumFormConfig("daysOfSearch"))
            {
                JSUtility.Alert(this, "查询日期间隔不能大于" + XmlUtility.GetNumFormConfig("daysOfSearch") + "天！");
                return;
            }
                    DataTable dt = salesmanBiz.GetRewardsLists(deptID, serWord, bTime, eTime,type);
                    gvList.DataSource = dt;
                    gvList.DataBind();
                    lbAmount.Text = dt.Rows.Count.ToString();
                
        }
       
        protected void btnExcel_Click(object sender, EventArgs e)
        {
           // ExcelUtility.GridViewToExcel(gvList, "SalesRewards.xls");
            string deptID = ddlDeptID.SelectedItem.Text.Trim();
            if (deptID == "请选择部门") deptID = "";
            string serWord = txtSerWord.Text.Trim();
            string bTime = txtBtime.Text.Trim();
            string eTime = txtEtime.Text.Trim();
            string type = ddlType.SelectedValue;
            if (type == "0" && deptID == "" && string.IsNullOrEmpty(serWord) && string.IsNullOrEmpty(bTime))
            {
                bTime = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                txtBtime.Text = bTime;
                txtEtime.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
            }

            if (StringUtility.GetDiffDays(bTime, eTime) > XmlUtility.GetNumFormConfig("daysOfSearch"))
            {
                JSUtility.Alert(this, "查询日期间隔不能大于" + XmlUtility.GetNumFormConfig("daysOfSearch") + "天！");
                return;
            }

            ExcelUtility.ExportDsToXls(this, salesmanBiz.GetRewardsLists(deptID, serWord, bTime, eTime,type), "SalesRewards.xls");
        }
        //增加信息
        protected void btnAdd_Click(object sender, EventArgs e)
        {

        }

        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F3F8F8'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            }
        }
    }
}